package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.CommonApplicationService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @描述 首页-->用户常用功能
 * @创建人 zm
 * @创建时间 2019/12/1
 */
@RestController
@RequestMapping("/commonapplication")
public class CommonApplicationController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CommonApplicationService commonApplicationService;

    /**
     * @描述 查询常用的功能
     * @创建人 zm
     * @创建时间 2019/12/1
     */
    @RequestMapping("/queryfunction")
    public Result queryFunction(RequestParameterWrapper request) {
        String admin = request.getParam("admin");
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        logger.info("admin={},schoolId={},teacherId={}", admin, schoolId, teacherId);
        return new Result(commonApplicationService.queryFunction(admin, schoolId, teacherId));
    }

    /**
     * @描述 查询全部二级菜单的功能
     * @创建人 zm
     * @创建时间 2019/12/1
     */
    @RequestMapping("/queryfunctionfindall")
    public Result queryFunctionFindAll(RequestParameterWrapper request, @RequestParam(value = "type", required = false) Integer type) {
        String admin = request.getParam("admin");
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        logger.info("admin={},schoolId={},teacherId={}", admin, schoolId, teacherId);
        return new Result(commonApplicationService.queryFunctionFindAll(admin, schoolId, teacherId, type));
    }

    /**
     * @描述 批量添加，常用功能菜单
     * @创建人 zm
     * @创建时间 2019/12/1
     */
    @RequestMapping("/addfunction")
    public Result addFunction(RequestParameterWrapper request, @RequestParam(value = "ids", required = true) Integer[] ids) {
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        logger.info("schoolId={},teacherId={}", schoolId, teacherId);
        int i = commonApplicationService.addFunction(schoolId, teacherId, ids);
        if (i > 0) {
            return new Result(CodeUtil.SUCCESS);
        }
        return new Result(CodeUtil.ADD_FAILURE);
    }
}
